package com.yulongtian.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yulongtian.entity.TemHumData;
import com.yulongtian.service.TemHumDataService;
import com.yulongtian.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 前端控制器 数据分析
 * </p>
 *
 * @author yulongtian
 * @since 2022-11-15
 */
@RestController
@RequestMapping("/temHumData")
@Api(tags = "数据管理和数据分析")
public class TemHumDataController {


    @Autowired
    private TemHumDataService temHumDataService;

    /**
     * 返回所有的设备编号下的数据
     *
     * @return
     */
    @GetMapping("/getDataByDeviceCode")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "返回所有的设备编号下的数据", notes = "传入设备编号deviceCode")
    public R getDataByDeviceCode(String deviceCode) {
        List<TemHumData> res = temHumDataService.getDataByDeviceCode(deviceCode);
        return R.ok().data("data", res);
    }


    /**
     * 返回所有的设备编号下的数据  模糊分页查询
     *
     * @return
     */
    @GetMapping("/getDataByDeviceCodePage")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "返回所有的设备编号下的数据  模糊分页查询", notes = "传入设备编号deviceCode")
    public R getDataByDeviceCodePage(String deviceCode, String bigTem, String smlTem, String bigHum, String smlHum,
                                     String bigAdcx, String smlAdcx, String beep, String led, String bigCreateTime, String smlCreateTime) {
        List<TemHumData> res = temHumDataService.getDataByDeviceCodePage(deviceCode, bigTem, smlTem, bigHum, smlHum, bigAdcx, smlAdcx, beep, led, bigCreateTime, smlCreateTime);
        return R.ok().data("data", res);
    }

    /**
     * 根据ID逻辑删除一条数据
     *
     * @param id
     * @return
     */
    @GetMapping("/deleteById")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据ID逻辑删除一条数据", notes = "传入ID")
    public R deleteById(String id) {
        temHumDataService.deleteById(id);
        return R.ok();
    }

    /**
     * 文件导出模糊查询的结果到excel
     *
     * @return: void
     */
    @GetMapping("/download")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "导出", notes = "传入模糊搜索条件")
    public void fileOutExcel(HttpServletResponse response, String deviceCode, String bigTem, String smlTem, String bigHum, String smlHum,
                             String bigAdcx, String smlAdcx, String beep, String led, String bigCreateTime, String smlCreateTime) {
        temHumDataService.getFileOutExcel(response, deviceCode, bigTem, smlTem, bigHum, smlHum, bigAdcx, smlAdcx, beep, led, bigCreateTime, smlCreateTime);
    }


    //***************************************************************数据分析******************************************************************************
    //***************************************************************数据分析******************************************************************************

    // 折线图显示 温度 湿度 光照强度 传入时间范围

    /**
     * 折线图显示的数据
     *
     * @return: void
     */
    @GetMapping("/zheXianTuShowTem")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "折线图显示的数据", notes = "设备编号和起止时间")
    public R zheXianTuShowTem(String deviceCode, String bigCreateTime, String smlCreateTime) {
        HashMap<String, Object> res = temHumDataService.zheXianTuShowTem(deviceCode, bigCreateTime, smlCreateTime);
        return R.ok().data(res);
    }



}

